using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GameAOT;

namespace IQIGame.Onigao.GamePlay
{
    public class UISearchPanel : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UISearchPanel
        {
            #region ObjectBinding Generate
            public IQIGame.Onigao.Framework.ExText searchId { protected set; get; }
            public IQIGame.Onigao.Framework.ExButton btnRecommand { protected set; get; }
            public IQIGame.Onigao.Framework.ExButton btnSearch { protected set; get; }
            public IQIGame.Onigao.Framework.ExText txtId { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("searchId", out var __tbv0);
                this.searchId = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("btnRecommand", out var __tbv1);
                this.btnRecommand = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExButton>("btnSearch", out var __tbv2);
                this.btnSearch = __tbv2;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("txtId", out var __tbv3);
                this.txtId = __tbv3;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify



        #region fields



        #endregion fields

        #region properties

        protected UIB_UISearchPanel ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => this._msgDispatcher as UIMsgDispatcher;

        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UISearchPanel();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
            this.ui.txtId.text += GameDataCenter.PlayerData.guid.ToString();
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {
            this.ui.btnRecommand.AddClickEvent(OnClickRecommand);
            this.ui.btnSearch.AddClickEvent(OnClickSearch);
        }

        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {

        }

        protected override void OnDispose()
        {

        }

        #region methonds
        private void OnClickSearch()
        {
            string txtId = this.ui.searchId.text;
            FriendModule.Instance.SearchPlayer(txtId).Forget();
        }

        private void OnClickRecommand()
        {
            FriendModule.Instance.RecommandPlayer().Forget();
        }




        #endregion methonds
    }
}